I would like to convert or create a new variable o...
# typescript
e
I would like to convert or create a new variable of type string based on the hubEnv(pulumi.Outputstring) variable. Something like this const peeringName = shrdConfig.get("env") + "2" + hubEnv. Below is the error I get when attempting to concatenate 2 differently typed variables. const hub = new pulumi.StackReference("acme/hub/gcp.sndbx"); const hubVpcSelfLink = hub.getOutput("networkSelfLink"); const hubEnv = hub.getOutput("env") Type Name pulumipulumiStack shared-gcp.sndbx.prod └─ gcpcomputeNetworkPeering sbxprod2Calling [toString] on an [OutputT] is not supported. To get the value of an OutputT as an Output Diagnostics: gcpcomputeNetworkPeering (sbxprod2Calling [toString] on an [OutputT] is not supported. To get the value of an OutputT as an Outputstring consider either: 1: o.apply(v =>
prefix${v}suffix
) 2: pulumi.interpolate
prefix${v}suffix
See https://www.pulumi.com/docs/concepts/inputs-outputs for more details. This function may throw in a future version of @pulumi/pulumi.): error: gcpcompute/networkPeeringNetworkPeering resource 'sbxprod2Calling [toString] on an [OutputT] is not supported. To get the value of an OutputT as an Outputstring consider either: 1: o.apply(v =>
prefix${v}suffix
) 2: pulumi.interpolate
prefix${v}suffix
See https://www.pulumi.com/docs/concepts/inputs-outputs for more details. This function may throw in a future version of @pulumi/pulumi.' has a problem: "name" ("sbxprod2Calling [toString] on an [OutputT] is not supported.\n\nTo get the value of an OutputT as an Outputstring consider either\n1 o.apply(v =>
prefix${v}suffix
)\n2: pulumi.interpolate `prefix${v}suffix`\n\nSee https://www.pulumi.com/docs/concepts/inputs-outputs for more details.\nThis function may throw in a future version of @pulumi/pulumi.") doesn't match regexp "^(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)$". Examine values at 'sbxprod2Calling [toString] on an [OutputT] is not supported.
l
That isn't related to concatenation. This is the important part of the error message:
Calling [toString] on an [Output<T>] is not supported.
The problem is that you're doing a "now" calculation using a future value. "networkSelfLink" isn't available yet, only the Output wrapper around it is.
You probably want to do the calculation in the future, inside an
apply()
. Are you passing this value to an arg parameter of a resource constructor? You can pass outputs in there and Pulumi will unwrap them in the future, when the values are available.
Note that you cannot use this value as the 1st param of a resource constructor. You can pass it into the 2nd param (the args), but not the 1st param.
This would be valid (pseudocode, obviously):
Copy code
const peeringResource = new PeeringResource("peeringAtoB", {
  name: hubEnv.apply((hub) => shrdConfig.get("env") + "2" + hub).
  anotherArg: ...
  ...
});
If you need multiple outputs to be available inside the same fat-arrow function, you need to use
pulumi.all()
. https://www.pulumi.com/docs/concepts/inputs-outputs/all/
There is also a convenience method,
pulumi.interpolate
, that is sugar around
pulumi.all()
. It's described on the same page.
e
@little-cartoon-10569 that sounds great, thank you, I will give it all a try
👍 1
@little-cartoon-10569 I used your pseudocode(roughly) and it worked perfectly, thank you
partypus 1